import doWithMap from './map';

const doWithCode = (code, params={}, data={}) => {
  const { error = {} } = data;
  doWithMap(error);

  switch(code){
    case -996:
      break;
  }
};

const fail = (data, reject, params = {}) => {
  wx.hideLoading();

  const { error = {} } = data;
  const { code, message = '网络异常' } = error;

  doWithCode(code, params, data);

  if (!params.silence){
    wx.showToast({
      icon: 'none',
      title: message
    });
  }

  console.log(params.api + '方法报错：');
  console.log(JSON.stringify(params.data || {}));
  console.log(JSON.stringify(err));

  app.error('事件:' + params.api + '方法报错，', '参数:' + JSON.stringify(params.data || {}) + '，', '返回:' + JSON.stringify(err));

  reject({
    success: false,
    data
  });
};
module.exports = fail;
